﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Windows.Forms;
using System.Data;

namespace libDAL
{
    public class clsDALOLEDB
    {
        private OleDbConnection _Connection;
        private OleDbDataAdapter[] _DataAdapter;
       // private OleDbCommandBuilder _CommandBuilder;
        private string strConnString = string.Empty;
      

        public clsDALOLEDB(string strConString)
        {
            try
            {
                _DataAdapter = new OleDbDataAdapter[1];
                strConnString = strConString; 
                set_connect();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " clsBusOLEDB"); 
            }
        }

        private void set_connect()
        {
            _Connection = new OleDbConnection(strConnString);
        }

        private OleDbConnection Get_Connection()
        {
            try
            {
                if (_Connection.State ==ConnectionState.Closed)
                {
                    _Connection.Open();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " Get_Connection");
            }
            return _Connection;
        }

        public DataTable get_dtSource(string strQuery)
        {
            DataTable dt = new DataTable();
            try
            {
                OleDbCommand cmd = new OleDbCommand(strQuery, Get_Connection());
                OleDbDataAdapter oledbDa = new  OleDbDataAdapter(cmd);
                oledbDa.SelectCommand.CommandTimeout = 0;
                oledbDa.Fill(dt);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " get_dtSource");
            }
            return dt;
        }
    }
}
